package com.ruike.alisurface.ui.settings;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.ruike.alisurface.R;
import com.ruike.alisurface.base.BaseAty;
import com.ruike.alisurface.broadcastReceiver.NetWorkBroadcastReceiver;
import com.ruike.alisurface.broadcastReceiver.TimeOutBroadcastReceiver;
import com.ruike.alisurface.ui.SystemStart_Aty;
import com.ruike.alisurface.utils.APPUtils;
import com.voodoo.lib_frame.manager.ActivityManager;
import com.voodoo.lib_logcat.L;

import butterknife.BindView;

/**
 * 网络异常页
 */
public class NetWork_Aty extends BaseAty {
    @BindView(R.id.restBoot_tv)
    TextView mRestBoot_tv;
    TimeOutBroadcastReceiver mTimeOutBroadcastReceiver;

    @Override
    protected int getLayoutResId() {
        return R.layout.app_network_error;
    }

    @Override
    protected void initViews() {
        initTitleBar(true);
    }

    @Override
    protected void initData() {
        L.i(" 网络异常页...启动");
        ActivityManager.getInstance().killOtherActivity();
        mRestBoot_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTimeOutBroadcastReceiver.infoRest();
                APPUtils.RestBoot();
            }
        });
    }


    @Override
    public void onNetworkChange(boolean isConnect, NetWorkBroadcastReceiver.NetworkType networkType, int signalStrength, NetWorkBroadcastReceiver.NetworkLevel level) {
        super.onNetworkChange(isConnect, networkType, signalStrength, level);
        if (isConnect) {
            L.e("有网络了，进行 软件重启");
            if (mTimeOutBroadcastReceiver != null) {
                mTimeOutBroadcastReceiver.infoRest();
            }
            startActivity(new Intent(this, SystemStart_Aty.class));
            finish();
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        mTimeOutBroadcastReceiver = new TimeOutBroadcastReceiver();
        mTimeOutBroadcastReceiver.initTimePrompt(this);

    }

    @Override
    protected void onPause() {
        super.onPause();
        mTimeOutBroadcastReceiver.unitTimePrompt(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        mTimeOutBroadcastReceiver = null;
        L.i(" 网络异常页...销毁");
    }
}
